package com.th.apicenter.baidu;

import com.alibaba.fastjson.JSON;
//import com.taobao.api.DefaultTaobaoClient;
//import com.taobao.api.TaobaoClient;
//import com.taobao.top.DefaultTopApiClient;
//import com.taobao.top.TopApiClient;
//import com.taobao.top.ability374.Ability374;
//import com.taobao.top.ability374.request.TaobaoTbkActivityInfoGetRequest;
//import com.taobao.top.ability374.response.TaobaoTbkActivityInfoGetResponse;
import com.th.apicenter.baidu.entity.ThBaiduData;
import com.th.apicenter.baidu.service.BaiduService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author kay
 * @date 2025/6/23
 * @TODO
 */
@RestController
@RequestMapping("/baidu")
@Slf4j
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    /**
     *  https://apibiz.tinghongzz.com/baidu/receive?account_id=001&callType=2&userid=__USER_ID__&callback_url=__CALLBACK_URL__&click_id=__CLICK_ID__&idfa=__IDFA__&imei_md5=__IMEI__&oaid=__OAID__&ip=__IP__&os_type&__OS_TYPE__&caid=__CAID__
     */
    @GetMapping("/receive")
    public void receiveUrl(@RequestParam(name = "account_id", required = false) String account_id,
                           @RequestParam(name = "userid", required = false) String userid,
                           @RequestParam(name = "callback_url", required = false) String callback_url,
                           @RequestParam(name = "click_id", required = false) String click_id,
                           @RequestParam(name = "idfa", required = false) String idfa,
                           @RequestParam(name = "imei_md5", required = false) String imei_md5,
                           @RequestParam(name = "ip", required = false) String ip,
                           @RequestParam(name = "os_type", required = false) String os_type,
                           @RequestParam(name = "tokenid", required = false) String tokenid,
                           @RequestParam(name = "oaid", required = false) String oaid,
                           @RequestParam(name = "caid", required = false) String caid) {
        ThBaiduData thBaiduData = new ThBaiduData();
        thBaiduData.setAccountId(account_id);
        thBaiduData.setUserid(userid);
        thBaiduData.setCallbackUrl(callback_url);
        thBaiduData.setClickId(click_id);
        thBaiduData.setIdfa(idfa);
        thBaiduData.setImeiMd5(imei_md5);
        thBaiduData.setIp(ip);
        thBaiduData.setOsType(os_type);
        thBaiduData.setTokenid(tokenid);
        thBaiduData.setOaid(oaid);
        thBaiduData.setCaid(caid);
        thBaiduData.setCreateTime(new Date());
        baiduService.receive(thBaiduData);
    }

//    public static void main(String[] args) throws Exception {
//        // create Client
//        TopApiClient client = new DefaultTopApiClient("<your-appkey>","<your-appsecret>","<top-gateway-url>");
//        Ability3197 apiPackage = new Ability3197(client);
//        // create domain
//        TaobaoTbkRtaConsumerMatchOfferList taobaoTbkRtaConsumerMatchOfferList = new TaobaoTbkRtaConsumerMatchOfferList();
//        taobaoTbkRtaConsumerMatchOfferList.setOfferId("123");
//        taobaoTbkRtaConsumerMatchOfferList.setTljUrl("https://www.taobao.com");
//        taobaoTbkRtaConsumerMatchOfferList.setItemId("1");
//
//        // create request
//        TaobaoTbkRtaConsumerMatchRequest request = new TaobaoTbkRtaConsumerMatchRequest();
//        request.setAdzoneId(33);
//        /*
//            [  {  "offer_id": 1  },  {  "offer_id": 2  }  ]
//        */
//        request.setOfferList(new ArrayList<TaobaoTbkRtaConsumerMatchOfferList>());
//        request.setSpecialId("1");
//        request.setDeviceValue("ssss");
//        request.setDeviceType("OAID");
//        /*
//            123456
//        */
//        request.setStrategyIdList(new ArrayList<String>());
//
//        TaobaoTbkRtaConsumerMatchResponse response = apiPackage.taobaoTbkRtaConsumerMatch(request);
//        if(!response.isSuccess()){
//            System.out.println(response.getSubMsg());
//        }
//        System.out.println(JSON.toJSONString(response));
//    }


}
